package edu.cuit.avatar.common.handler;

import edu.cuit.avatar.common.BeanUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

/**
 * 将单行记录结果集处理为具体类型的JavaBean实例
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/26 10:43
 */
public class BeanResultHandler<T> implements ResultSetHandler<T>{
    private Class<T> clazz;

    public BeanResultHandler(Class<T> clazz) {
        this.clazz = clazz;
    }

    @Override
    public T process(ResultSet rs) throws SQLException {
        Map<String, ?> map = new MapResultSetHandler().process(rs);
        return BeanUtils.map2bean(map, clazz);
    }
}
